﻿using CommonType;
using MediatR;
using S_Incident.API.Application.Commands;
using S_Incident.Infrasturctre.Interface;

namespace S_Incident.API.Application.CommandsHanders
{
    public class MyEventsSqlSuagerDeleteCommandHanders : IRequestHandler<MyEventsSqlSuagerDeleteCommand, ApiResule<int>>
    {
        private readonly IEventDispositionRepository eventDisposition;

        public MyEventsSqlSuagerDeleteCommandHanders(IEventDispositionRepository eventDisposition)
        {
            this.eventDisposition = eventDisposition;
        }
        /// <summary>
        /// 删除我的事件
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResule<int>> Handle(MyEventsSqlSuagerDeleteCommand request, CancellationToken cancellationToken)
        {
            var smilt = await eventDisposition.GetFindAsync(request.Id);
            smilt.IsDel = true;
            var result = await eventDisposition.UpdateAsync(smilt);
            if (result > 0)
            {
                return new ApiResule<int>
                {
                    Code = 200,
                    Msg = "删除成功",
                    Result = result
                };
            }
            else
            {
                return new ApiResule<int>
                {
                    Code = 250,
                    Msg = "删除失败",
                    Result = result
                };
            }
        }
    }
}
